package main.examination.NetEase;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/** 男女配对 */
public class ex4 {
    private static Map<Integer, Node> map;

    /** ac0 */
    public static void main(String[] args) {
        map = new HashMap<>();
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextLine().split(" ").length;
        int num2 = sc.nextLine().split(" ").length;
        int n = sc.nextInt();
        boolean[][] people = new boolean[n][n];
        Node[] in = new Node[n];
        for (int i = 0; i < n; i++) {
            in[i] = new Node(i);
            map.put(i, in[i]);
        }
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int cpId = sc.nextInt();
            people[id][cpId] = true;
            people[cpId][id] = true;
            ++in[id].in;
            ++in[cpId].in;
        }
        System.out.println(solution(people, num1, num2, in));
    }

    private static int solution(boolean[][] people, int num1, int num2, Node[] in) {
        int n = in.length;
        boolean b = true;
        while (b) {
            Arrays.sort(in, Comparator.comparingInt(o -> o.in));
            b = false;
            int index = 0;
            while (index < n && in[index].isVisited) {
                ++index;
            }
            if (index == n) {
                break;
            }
            Node node = in[index];
            int i = node.val;
            boolean[] person = people[i];
            boolean flag = true;
            for (int j = 0; j < n; j++) {
                if (person[j] && flag) {
                    flag = false;
                    clear(people, j, i);
                    b = true;
                } else if (person[j]) {
                    person[j] = false;
                    people[j][i] = false;
                    map.get(j).in--;
                    b = true;
                }
            }
            node.in = 1;
            node.isVisited = true;
        }
        int res = 0;
        for (int i = 0; i < num1; i++) {
            for (int j = 0; j < num2; j++) {
                if (people[i][num1 + j]) {
                    ++res;
                }
            }
        }
        return res;
    }

    private static void clear(boolean[][] people, int id, int cpId) {
        boolean[] cp = people[id];
        for (int i = 0; i < cp.length; i++) {
            if (i != cpId) {
                cp[i] = false;
                people[i][id] = false;
                map.get(i).in--;
            }
        }
        map.get(id).in = 1;
        map.get(id).isVisited = true;
    }

    private static class Node {
        int val;
        int in;
        boolean isVisited;

        public Node(int val) {
            this.val = val;
        }
    }
}
